 *Author AA
*Date 06/03/2025 


clear all


** Conditional Path Structure
*Ashani's Paths

if "`c(username)'" == "ashaniamarasinghe" & "`c(os)'"=="MacOSX" {
	global mainpath "/Users/ashaniamarasinghe/Dropbox/Youtube"
	}

if "`c(username)'" == "aama7224" & "`c(os)'"=="MacOSX" {
	global mainpath "/Users/aama7224/Dropbox/Youtube"
	}



global data "empirics/analysis/data"
global fig "empirics/analysis/fig"
global tab "empirics/analysis/tab"
global est "empirics/analysis/est"



cd $mainpath

set scheme plotplainblind

*baseline estimates

use $data/gid_month_panel.dta, clear

*Table 1 - Panel A - ACLED
reghdfe var1pred_idw_pop_w_std AC_total_fatalities_pop_w, noabsorb cl(gid) nocons 
outreg2  using $tab/Table_1A.doc, dec(4) replace addtext(Grid FE, No, Year FE, No, Month FE, No)

reghdfe var1pred_idw_pop_w_std AC_total_fatalities_pop_w, absorb(gid) cl(gid) nocons
outreg2  using $tab/Table_1A.doc, dec(4) append addtext(Grid FE, Yes, Year FE, No, Month FE, No)

reghdfe var1pred_idw_pop_w_std AC_total_fatalities_pop_w, absorb(gid year) cl(gid) nocons
outreg2  using $tab/Table_1A.doc, dec(4) append addtext(Grid FE, Yes, Year FE, Yes, Month FE, No)

reghdfe var1pred_idw_pop_w_std AC_total_fatalities_pop_w, absorb(gid year month) cl(gid) nocons resid
outreg2  using $tab/Table_1A.doc, dec(4) append addtext(Grid FE, Yes, Year FE, Yes, Month FE, Yes)


**Figure 6A

gen ACLED_reghdfe_resid_abs=abs(_reghdfe_resid)
 
scatter _reghdfe_resid AC_total_fatalities, ylab(-0.2(0.2)0.6) xtitle("Fatalities(iym)", size(large)) ytitle("Resdiuals(iym)", size(large))
 graph export $fig/Figure_6A.png, as(png) replace

 
**Figure 6C
scatter _reghdfe_resid marg_index_2020, ylab(-0.2(0.2)0.6) xtitle("Marginalisation(2020)", size(large)) ytitle("Resdiuals(iym)", size(large))
 graph export $fig/Figure_6C.png, as(png) replace

**Figure 7A

collapse (mean) ACLED_reghdfe_resid_abs, by (gid _ID)

*visualizing absolute error
colorpalette HSV blues, n(8) nograph reverse
local colors `r(p)'
spmap ACLED_reghdfe_resid_abs using $raw/priogrid_mex/priogrid_mex_coordinates, ///
 id(_ID) clm(q)  fcolor("`colors'") ///
 ocolor(gs15 ..) osize(0.02 ..) ///
ndfcolor(white) ndocolor(gs15 ..) ndsize(0.02 ..) ndlabel("No data") ///
 polygon(data($raw/priogrid_mex/priogrid_mex_coordinates) ocolor(gs8) osize(0.03) legenda(off) ) ///
 legend(pos(7) size(3) )  legstyle(2) 
 graph export $fig/Figure_7A.png, as(png) replace


 
 
*Table 1 - Panel B - Homicides
 
use $data/gid_month_panel.dta, clear

reghdfe var1pred_idw_pop_w_std crime_count_pop_w, noabsorb cl(gid) nocons
outreg2  rename(crime_count_pop_w "crime_count" var1pred_idw "Geographic Violence Perception Index") using $tab/Table_1B.doc, dec(4) replace addtext(Grid FE, No, Year FE, No, Month FE, No)

reghdfe var1pred_idw_pop_w_std crime_count_pop_w, absorb(gid) cl(gid) nocons
outreg2  rename(crime_count_pop_w "crime_count" var1pred_idw "Geographic Violence Perception Index") using $tab/Table_1B.doc, dec(4) append addtext(Grid FE, Yes, Year FE, No, Month FE, No)

reghdfe var1pred_idw_pop_w_std crime_count_pop_w, absorb(gid year) cl(gid) nocons
outreg2  rename(crime_count_pop_w "crime_count" var1pred_idw "Geographic Violence Perception Index") using $tab/Table_1B.doc, dec(4) append addtext(Grid FE, Yes, Year FE, Yes, Month FE, No)

reghdfe var1pred_idw_pop_w_std crime_count_pop_w, absorb(gid year month) cl(gid) nocons resid
outreg2  rename(crime_count_pop_w "crime_count" var1pred_idw "Geographic Violence Perception Index") using $tab/Table_1B.doc, dec(4) append addtext(Grid FE, Yes, Year FE, Yes, Month FE, Yes)



**Figure 6B
gen crime_reghdfe_resid_abs=abs(_reghdfe_resid)
scatter _reghdfe_resid AC_total_fatalities, ylab(-0.2(0.2)0.6) xtitle("Homicides(iym)", size(large)) ytitle("Resdiuals(iym)", size(large))
 graph export $fig/Figure_6B.png, as(png) replace

 
 **Figure 6D
scatter _reghdfe_resid marg_index_2020, ylab(-0.2(0.2)0.6) xtitle("Marginalisation(2020)", size(large)) ytitle("Resdiuals(iym)", size(large))
 graph export $fig/Figure_6D.png, as(png) replace

 
 
 
**Figure 7B

collapse (mean) crime_reghdfe_resid_*, by (gid _ID)

*visualizing absolute error
colorpalette HSV blues, n(8) nograph reverse
local colors `r(p)'
spmap crime_reghdfe_resid_abs using $raw/priogrid_mex/priogrid_mex_coordinates, ///
 id(_ID) clm(q)  fcolor("`colors'") ///
 ocolor(gs15 ..) osize(0.02 ..) ///
ndfcolor(white) ndocolor(gs15 ..) ndsize(0.02 ..) ndlabel("No data") ///
 polygon(data($raw/priogrid_mex/priogrid_mex_coordinates) ocolor(gs8) osize(0.03) legenda(off) ) ///
 legend(pos(7) size(3) )  legstyle(2) 
 graph export $fig/Figure_7B.png, as(png) replace


 **END
 
 
